<template>
  <div class="page" style="">
    <div class="print_title">员工试用期考核表 · 禾美环保</div>
    <p class="title">基础信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px; margin: 0 0 14px 0;">
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >员工姓名:</p>
            <!-- <p style="margin-bottom: 0; white-space: nowrap" >{{ formData }}</p> -->
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ employeeId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >人员编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.employeeNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >性别:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ filterMultiDictText(this.dictOptions['gender'], formData.gender + '') }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >岗位:</p>
            <!-- <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.positionId_dictText }}</p> -->
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ filterMultiDictText(this.dictOptions['positionId'], formData.positionId + '') }}</p>
          </a-col>
        </a-row>
      </a-col>

      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >入职时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.partTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >试用期满时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.endTime }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>
    
    <p class="title">评测信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px; margin: 0 0 14px 0;">
      <div v-for="(item, key) in question" :key="key">
        <a-col :span="24">
          <p style="margin-bottom: 0; white-space: nowrap" >{{ item.title }}:</p>
        </a-col>
        <a-col :span="24" v-for="(temp, index) in item.children" :key="index">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap" >{{ temp.title }}:</p>
              <div v-for="(choice, value) in temp.children" :key="value">
                <p style="margin:0 0 0 6px; word-break: break-all;" v-if="choice.code == question[key].children[index].value">{{ choice.title }}</p>
              </div>
            </a-col>
          </a-row>
        </a-col>
      </div>
    </a-row>

    <p class="title">评测结果</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px; margin: 0 0 14px 0;">
      <a-col :span="24" style="background-color:#F1F1FF">
        <div style="font-weight:bold">说明：A优秀 ：95分以上可提前2个月转正；B优良：90分以上可提前1个月转正；C较好：75（含）-90分可正常转正；D一般：60-75分延长试用；E较差：60分以下终止试用。</div>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >考核得分:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.evaluatingResult }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >评测人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ filterMultiDictText(this.dictOptions['evaluatingEmployee'], formData.evaluatingEmployee + '') }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >评测时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.evaluatingTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap" >评价:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.evaluationPeriod }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>

    <!-- 附件信息 -->
    <FileInfor :purchaseFile="purchaseFile" v-if="purchaseFile && purchaseFile.length"></FileInfor>
    <!-- 流程详情 -->
    <ProcessInfor v-if="formData.bpmStatus !== '1' && dataHistorySource && dataHistorySource.length" :dataHistorySource="dataHistorySource"></ProcessInfor>
  </div>
</template>
<script>
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
  import { getAction, getFileAccessHttpUrl } from '@/api/manage'
  import FileInfor from '@/components/print/FileInfor.vue' // 审批历史流程列表组件
  import ProcessInfor from '@/components/print/ProcessInfor.vue' // 审批历史流程列表组件
  import address from '@/components/AddressChoice/address.js'
  import moment from 'moment';
  export default {
    props: {
      formBpm: {
        type: Boolean,
        default: false
      },
      formData: {
        type: Object,
        default: () => {},
        required: true
      },
      formDataHistory: {
        type: Object,
        default: () => {}
      },
      question: {
        type: Array,
        default: () => []
      }
    },
    components: {
      FileInfor,
      ProcessInfor
    },
    data() {
      return {
        filterMultiDictText,
        employeeId_dictText: '',
        moment,
        address, // code地址
        getFileAccessHttpUrl,
        dictOptions: {},
        dataHistorySource: [], // 流程列表
        url: {
            historyList: '/api/erpmng/act/task/processHistoryList', // 流程历史跟踪接口
            queryById: '/api/erp/administration/seal/erpSealAuthorizationInformation/queryById', // 獲取詳情
            queryByUserId: '/api/erpmng/sys/user/queryByEmpId',
            queryByUserIds: '/api/erpmng/sys/user/queryByEmpIds'
        },
        purchaseFile: [], // 附件
        ids_dictText: '' // 印章
      };
    },
    watch: {
      formData: {
        handler (val) {
            if (val) {
              // this.getHistoryList()
              this.initDictConfig()
              this.initObj(val.employeeId)
              if (val.attachment) {
                this.purchaseFile = val.attachment.split(',')
              }
            }
        },
        immediate: true
      }
    },
    methods: {
      // 获取列表
      getHistoryList() {
        var params = { processInstanceId: this.formDataHistory.procInsId };// 查询条件
        getAction(this.url.historyList, params).then(res => {
            if (res.success) {
                this.dataHistorySource = res.result.records || res.result
            }
        })
      },

      initObj(empId) {
        if (empId && empId.length > 0) {
          var empIdArr = empId.split(',');
          let url = '';
          let param = {};
          if (empIdArr.length == 1) {
            url = this.url.queryByUserId;
            param = { empId: empId };
          } else {
            url = this.url.queryByUserIds;
            param = { empId: empId };
          }
          getAction(url, param).then((res) => {
            console.log('------------res', res)
            if (res.success) {
              if (!Array.isArray(res.result)) {
                this.employeeId_dictText = res.result.realname
              } else {
                this.employeeId_dictText = ''
                // for (let i = 0; i < res.result.length; i++) {
                //   this.selectedObj.push(res.result[i]);
                // }
                  res.result.map(value => {
                    this.employeeId_dictText = value.realname + ',' + this.employeeId_dictText
                  })
                  if (this.employeeId_dictText) {
                    this.employeeId_dictText = this.employeeId_dictText.substr(0, this.employeeId_dictText.length - 1)
                  }
              }
            }
          });
        } else {
          this.employeeId_dictText = ''
        }
      },

      // 加载数据字典信息
      initDictConfig() {
        initDictOptions('sys_position,name,id,del_flag = 0 and audit_status=2').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'positionId', res.result)
          }
        })
        initDictOptions('gender').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'gender', res.result)
          }
        })
        initDictOptions('erp_employee_file,name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'evaluatingEmployee', res.result)
          }
        })
        // initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
        //   if (res.success) {
        //     this.$set(this.dictOptions, 'teamId', res.result)
        //   }
        // })
        // initDictOptions('sys_position,name,code').then((res) => {
        //   if (res.success) {
        //     this.$set(this.dictOptions, 'postCode', res.result)
        //   }
        // })
        // initDictOptions('YES_OR_NO').then((res) => {
        //   if (res.success) {
        //     this.$set(this.dictOptions, 'isDuty', res.result)
        //   }
        // })
        // initDictOptions('YES_OR_NO').then((res) => {
        //   if (res.success) {
        //     this.$set(this.dictOptions, 'isVirtual', res.result)
        //   }
        // })
        // initDictOptions('reward_punish_category').then((res) => {
        //   if (res.success) {
        //     this.$set(this.dictOptions, 'rewardPunishCategory', res.result)
        //   }
        // })
      },

      // 地址查询
      getArea(json, code) {
        let names = [];
        let codes = [];
        function findCity(list, code, father) {
          const index = list.findIndex(ev => {
            return ev.code === code;
          });

          if (index > -1) {
            const child = list[index];
            names.unshift(child.name);
            codes.unshift(child.code);
            father && names.unshift(father.name) && codes.unshift(father.code);
            father && findCity(json || [], father.code);
            return;
          }
          list.map(item => {
            if (item.children) {
              findCity(item.children || [], code, item);
            }
          });
        }
        findCity(json, code);
        names = [...new Set(names)];
        codes = [...new Set(codes)];
        return { codes, names };
      },

      tableRowClass(record, index) {
        console.log('record, index', record, index)
        if (index == 0) {
            return 'rowClass';
        }
        return ''
      }
    }
  };
</script>
<style lang="less" scoped>
  .page{
    background: #ffffff;
    padding: 19px 28px 0 28px;
    width: 750px;
    .print_title{
        font-size: 15px;
        font-family: Alibaba PuHuiTi 2.0;
        font-weight: normal;
        color: #000000;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 9px;
    }
    .title {
        background: #EEEEEE;
        font-size: 13px;
        font-family: Alibaba PuHuiTi 2.0;
        font-weight: normal;
        color: #000000;
        padding: 11px 9px;
    }
    .content {
        font-size: 13px;
    }

    .title_table{
        font-size: 13px;
        font-family: Alibaba PuHuiTi 2.0;
        font-weight: normal;
        color: #000000;
    }
  }
  /deep/ .rowClass{
      font-size: 10px;
      font-family: Alibaba PuHuiTi 2.0;
      font-weight: normal;
      color: #000000;
  }
  /deep/ .ant-table-thead th{
      font-size: 10px;
      font-family: Alibaba PuHuiTi 2.0;
      font-weight: normal;
      color: #000000;
  }
  /deep/ .ant-table-thead tr{
      background: #EEEEEE;
  }
  /deep/ .ant-table-small > .ant-table-content > .ant-table-body {
      margin: 0 0px;
  }
  /deep/ .ant-table-body tr {
      font-size: 10px;
      font-family: Alibaba PuHuiTi 2.0;
      font-weight: normal;
      color: #000000;
  }
  /deep/ .ant-table-body tr td {
    word-wrap:break-word;
    word-break:break-all;
  }
  .content {
    font-size: 13px;
  }
</style>
